Contourf

using GeoMakie, CairoMakie

lons = -180:180
lats = -90:90
# Create some field of values across `lons` and `lats`
# This grid can be of any density, but note that the
# time it takes to plot scales with the grid size!
field = [exp(cosd(l)) + 3(y/90) for l in lons, y in lats]

# Surface example
fig = Figure()
ax = GeoAxis(fig[1,1])
contourf!(ax, lons, lats, field; shading = false)

fig
Contourf

Axis configuration

using Makie, CairoMakie, GeoMakie

fig = Figure(resolution = (1000,1000))

axes = [GeoAxis(fig[i, j]) for i in 1:2, j in 1:2]

# axis 1 - I want an orthographic projection.
axes[1, 1].scene.transformation.transform_func[] = Proj.Transformation("+proj=latlong","+proj=ortho")
xlims!(axes[1, 1], -90, 90)

# axis 2 - wacky spines
axes[1, 2].topspinevisible = false
axes[1, 2].rightspinecolor = :red
axes[1, 2].spinewidth      = 5

# axis 3 - messing with grids
axes[2, 1].xgridcolor = :blue
axes[2, 1].xgridstyle = :dashdot
axes[2, 1].ygridcolor = (:orange, 0.5)
axes[2, 1].ygridwidth = 2.0

# axis 4 - customizing ticks
axes[2, 2].xticks = -180:10:180
axes[2, 2].xticklabelsvisible[] = false
hidexdecorations!(axes[2, 2])
fig
Axis configuration

Black Marble

using GeoMakie, CairoMakie, Makie
using Downloads

# Get and load data
file = Downloads.download("https://neo.sci.gsfc.nasa.gov/archive/blackmarble/2016/global/BlackMarble_2016_01deg_geo.tif")
img = rotr90(FileIO.load(file))

fig = Figure(resolution = (800, 400), backgroundcolor = :black)
ga = GeoAxis(fig[1, 1]; title = "Earth at night", titlecolor = :white, backgroundcolor = (:black, 0.0))
hidedecorations!(ga) # hide ticks and ticklabels

imgplot = image!(-180..180, -89.9..89.9, img; interpolate = false)

fig
# save at high resolution
# save("blackmarble.png", fig; px_per_unit = 2)
Black Marble

Italy's states

using CairoMakie, GeoMakie
using GeoMakie.GeoJSON
using Downloads
# Acquire data
it_states = Downloads.download("https://github.com/openpolis/geojson-italy/raw/master/geojson/limits_IT_provinces.geojson")
geo = GeoJSON.read(read(it_states, String))
basic = GeoMakie.geo2basic(geo)

fig = Figure()
ga = GeoAxis(fig[1, 1]; dest = "+proj=ortho +lon_0=12.5 +lat_0=42", lonlims=(12, 13), latlims = (40, 44))
plot!.(ga, basic; strokecolor = :blue, strokewidth = 1, color = (:blue, 0.5), shading = false);
datalims!(ga)

fig



fig_anim = Figure()
ga_anim = GeoAxis(fig_anim[1, 1]; dest = "+proj=ortho", lonlims=(-90,90), coastlines=true)

record(fig_anim, "try_3.mp4", 0:89) do i
    xlims!(ga_anim, -90+i, 90-i)
    ylims!(ga_anim, -90+i/2, 90-i/2)
end


record(fig_anim, "try_4.mp4", 0:89) do i
    xlims!(ga_anim, -90+i/2, 90-i)
    ylims!(ga_anim, -90+i, 90-i)
end
Italy's states

Projections

using GeoMakie, CairoMakie, Makie

lons = -180:180
lats = -90:90
field = [exp(cosd(l)) + 3(y / 90) for l in lons, y in lats]

fig = Figure()
ax1 = GeoAxis(fig[1, 1], dest = "+proj=vitk1 +lat_1=45 +lat_2=55",
    coastlines = true, title = "vitk1")
ax2 = GeoAxis(fig[1, 2], dest = "+proj=wintri",
    coastlines = true, title = "wintri")

surface!(ax1, lons, lats, field; shading = false, colormap = (:plasma, 0.45))
surface!(ax2, lons, lats, field; shading = false)
hidedecorations!(ax1)

fig
Projections

Orthographic projection

using GeoMakie, CairoMakie

# Limited-domain projections (like orthographic) must have
# their limits correctly set!
# If the limits are too large, you may get a blank figure.
fig = Figure()
ga = GeoAxis(
    fig[1, 1],
    dest="+proj=ortho",
    lonlims = Makie.automatic,
    coastlines = true,
    title = "Orthographic projection with proper limits"
)
# hidedecorations!(ga)
sp = surface!(ga, lons, lats, field; shading = false, colormap = :rainbow_bgyrm_35_85_c69_n256)
cb = Colorbar(fig[1, 2], sp)

fig
Orthographic projection

World Population centers

# This example was contributed by Martijn Visser (@visr)
using Makie, CairoMakie, GeoMakie
using GeoMakie.GeoJSON
using Downloads

source = "+proj=longlat +datum=WGS84"
dest = "+proj=natearth2"

fig = Figure(resolution = (1000,500))
ga = GeoAxis(
    fig[1, 1];
    source = source,
    dest = dest,
)

ga.xticklabelsvisible[] = false
ga.yticklabelsvisible[] = false

url = "https://raw.githubusercontent.com/nvkelso/natural-earth-vector/master/geojson/"
land = Downloads.download(url * "ne_110m_land.geojson")
land_geo = GeoJSON.read(read(land, String))
poly!(ga, land_geo, color=:black)

pop = Downloads.download(url * "ne_10m_populated_places_simple.geojson")
pop_geo = GeoJSON.read(read(pop, String))
scatter!(ga, GeoMakie.geo2basic(pop_geo), color="lightgrey", markersize=1.2)

fig
World Population centers

Field and countries

# This example was taken from Lazar Alonso's
# BeautifulMakie.jl repository.  It has some really
# good stuff - check it out!
using Makie, CairoMakie, GeoMakie
import Downloads
using GeoMakie.GeoJSON

# https://datahub.io/core/geo-countries#curl # download data from here
worldCountries = GeoJSON.read(read(Downloads.download("https://raw.githubusercontent.com/johan/world.geo.json/master/countries.geo.json"), String))
n = length(GeoMakie.GeoInterface.features(worldCountries))
lons = -180:180
lats = -90:90
field = [exp(cosd(l)) + 3(y/90) for l in lons, y in lats]


fig = Figure(resolution = (1200,800), fontsize = 22)

ax = GeoAxis(
    fig[1,1];
    dest = "+proj=wintri",
    title = "World Countries",
    tellheight = true,
)

hm1 = surface!(ax, lons, lats, field; shading = false)

hm2 = poly!(
    ax, worldCountries;
    color= 1:n,
    colormap = Reverse(:plasma),
    strokecolor = :black,
    strokewidth = 0.25
)

cb = Colorbar(fig[1,2], hm1, label = "variable, color code")

hidedecorations!(ax)

fig
Field and countries

GraphMakie with GeoMakie

# This example was adapted from code in https://discourse.julialang.org/t/combine-makie-with-gmt-jl/74347
using GeoMakie, CairoMakie
using GraphMakie, Graphs, Downloads
using GeoMakie.GeoJSON, GeoMakie.GeoInterface

states = Downloads.download("https://raw.githubusercontent.com/PublicaMundi/MappingAPI/master/data/geojson/us-states.json")
states_geo = GeoJSON.read(read(states, String))
# Get rid of Alaska
filter!((x->!(x.properties["name"] ∈ ("Alaska", "Hawaii", "Puerto Rico"))), states_geo.features)

n = length(GeoInterface.features(states_geo))

#g = wheel_graph(10)
gpos = Dict(
    (-96.5967, 38.9617) => "KSCYng",
    (-122.3, 47.6) => "STTLng",
    (-105.0, 40.75) => "DNVRng",
    (-122.026, 37.3858) => "SNVAng",
    (-87.6167, 41.8333) => "CHINng",
    (-85.5, 34.5) => "ATLAng",
    (-77.0268, 38.8973) => "WASHng",
    (-73.9667, 40.7833) => "NYCMng",
    (-86.1595, 39.7806) => "IPLSng",
    (-95.5174, 29.77) => "HSTNng",
    (-118.25, 34.05) => "LOSAng",
    (-84.3833, 33.75) => "ATLAM5")

g = complete_graph(length(keys(gpos)))
positions = Point2f.(collect(keys(gpos)))

fig = Figure(resolution = (1200, 800), fontsize = 22)
ga = GeoAxis(
    fig[1, 1],
    source = "+proj=longlat +datum=WGS84",
    dest = "+proj=lcc +lon_0=-100 +lat_1=33 +lat_2=45",
    title = "Projection: lcc +lon_0=-100 +lat_1=33 +lat_2=45",
    coastlines = false,
    lonlims = automatic, latlims = automatic,
)

poly!(
    ga, states_geo;
    color = 1:n, colormap = (:viridis, 0.25),
    strokecolor = :black, strokewidth = 1
)

graphplot!(
    ga, g;
    layout = _ -> positions, node_size = 1,
    edge_color = cgrad(:plasma)[LinRange(0, 1, 66)],
    node_color = cgrad(:plasma)[LinRange(0, 1, length(keys(gpos)))]
)

# Set the limits to the extrema of the data
# (this is why we removed Alaska)
datalims!(ga)

fig
GraphMakie with GeoMakie

Rotating Earth

using Makie, CairoMakie, GeoMakie

destnode = Observable("+proj=ortho")

fig = Figure()
ga = GeoAxis(
    fig[1, 1],
    coastlines = true,
    dest = destnode,
    lonlims = Makie.automatic
)
image!(-180..180, -90..90, rotr90(GeoMakie.earth()); interpolate = false)
hidedecorations!(ga)

record(fig, "rotating_earth_ortho.mp4"; framerate=30) do io
    for lon in -180:3:180
        ga.title[] = string(lon) * "°"
        destnode[] = "+proj=ortho +lon_0=$lon"
        xlims!(ga, lon-90, lon+90)
        recordframe!(io)
    end
end